import 'package:flutter/material.dart';

enum TagsTypeEnum { official, shopService, customer, other, freeCustomer }

class TagItem {
  TagItem(
      {required this.title,
      this.typeEnum = TagsTypeEnum.other,
      this.radius = 12});

  final TagsTypeEnum typeEnum;
  final String title;
  final double radius;
}

class TitleWithTags extends StatelessWidget {
  final TextSpan title;
  final List<TagItem> tags;

  const TitleWithTags({Key? key, required this.title, required this.tags})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Flexible(
            child: Text.rich(
              title,
              overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
              maxLines: 1, // 限制为一行
              style: const TextStyle(fontSize: 18),
            ),
          ),
          const SizedBox(width: 8), // 标签与标题之间的间距
          Wrap(
            spacing: 4, // 标签之间的间距
            children: tags.map((tag) {
              return Container(
                padding: EdgeInsets.symmetric(
                    horizontal: tag.typeEnum == TagsTypeEnum.official ? 2 : 4,
                    vertical: 2),
                decoration: BoxDecoration(
                  color: tag.typeEnum == TagsTypeEnum.official
                      ? Colors.red
                      : tag.typeEnum == TagsTypeEnum.shopService
                          ? Colors.orange
                          : tag.typeEnum == TagsTypeEnum.freeCustomer
                              ? Colors.blue
                              : Colors.green,
                  borderRadius: BorderRadius.circular(tag.radius),
                ),
                child: Text(
                  tag.title,
                  style: const TextStyle(
                      fontSize: 12, color: Colors.white, height: 1.1),
                ),
              );
            }).toList(),
          ),
          const SizedBox(
            width: 4,
          )
        ],
      ),
    );
  }
}
